package com.alibaba.controller;


import com.alibaba.bean.Data;
import com.alibaba.bean.PkResult;
import com.alibaba.service.PkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("pk")
public class PkController {
    @Autowired
    PkService pkService;
    @RequestMapping(value = "timepk", method = RequestMethod.POST)
    @ResponseBody
    public PkResult TimePk(@RequestParam("userId")int userId,@RequestParam("faceValue") float faceValue,@RequestParam("gender") int gender,@RequestParam("age")int age,@RequestParam("smile")float smile,@RequestParam("emotion")int emotion,@RequestParam("skinHealth")float skinHealth,@RequestParam("skinStain")float skinStain ,@RequestParam("skinAcne")float skinAcne,@RequestParam("skinDarkCircle")float skinDarkCircle,@RequestParam("imgUrl")String imgUrl,@RequestParam("hoursenum") int hoursenum){
        pkService.insertPk(userId, faceValue, gender, age, smile, emotion, skinHealth, skinStain, skinAcne, skinDarkCircle, imgUrl);
        if(pkService.selectHoursenum(hoursenum)==0){
            pkService.insertPk3(hoursenum);
        }
        if(pkService.selectUserId1(hoursenum)==-1&&pkService.selectUserId1(hoursenum)!=userId)
        {
            pkService.updatePk1(userId,hoursenum);
        }
        if(pkService.selectUserId1(hoursenum)!=userId&&pkService.selectUserId2(hoursenum)!=userId)
        {
            pkService.updatePk2(userId,hoursenum);
            PkResult pkResult=new PkResult();
            pkResult.setResult(true);
            pkResult.setData(null);
            pkResult.setErrorMsg("成功");
            return pkResult;

        }
        PkResult pkResult=new PkResult();
        pkResult.setResult(false);
        pkResult.setData(null);
        pkResult.setErrorMsg("还差一个数据");
        return pkResult;
    }

}
